//
//  GroupViewController.m
//  iMADE
//
//  Created by Ed Knutson on 10/20/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "GroupViewController.h"

#import "TransferGroup.h"
#import "EventViewController.h"
#import "NewsViewController.h"
#import "WebViewController.h"

@implementation GroupViewController

@synthesize group, logo, name, desc, logoImg, tags, newsBtn, eventsBtn, siteBtn;


- (void)viewDidLoad {
    [super viewDidLoad];

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
	self.title = group.name;
	
	name.text = group.name;
	desc.text = group.groupDescription;
	if(![[NSNull null] isEqual:logo])
		 logoImg.image = logo;
	NSArray *tagArray = group.tags;
	if(tagArray != nil && [tagArray count] > 0) {
		NSMutableString *tagStr = [[NSMutableString alloc] initWithString:[tagArray objectAtIndex:0]];
		for(int i=1; i<[tagArray count]; i++)
			[tagStr appendString:[@", " stringByAppendingString:[tagArray objectAtIndex:i]]];
		tags.text = tagStr;
		
	}
	
	if(group.rssUrl == nil)
		newsBtn.enabled = NO;
	else [newsBtn addTarget:self action:@selector(showNews) forControlEvents:UIControlEventTouchUpInside];
	if(group.icsUrl == nil)
		eventsBtn.enabled = NO;
	else [eventsBtn addTarget:self action:@selector(showEvents) forControlEvents:UIControlEventTouchUpInside];
	if(group.websiteUrl == nil)
		siteBtn.enabled = NO;
	else [siteBtn addTarget:self action:@selector(showSite) forControlEvents:UIControlEventTouchUpInside];
}


- (void)showNews {
	NewsViewController *anotherViewController = [[[NewsViewController alloc] initWithNibName:@"NewsViewController" bundle:nil] autorelease];
	anotherViewController.feedUrl = group.rssUrl;
	[self.navigationController pushViewController:anotherViewController animated:YES];
	
}


- (void)showEvents {
	EventViewController *anotherViewController = [[[EventViewController alloc] initWithNibName:@"EventViewController" bundle:nil] autorelease];
	anotherViewController.feedUrl = group.icsUrl;
	[self.navigationController pushViewController:anotherViewController animated:YES];
	}


- (void)showSite {
	WebViewController *anotherViewController = [[[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil] autorelease];
	anotherViewController.url = group.websiteUrl;
	[self.navigationController pushViewController:anotherViewController animated:YES];
	
}


/*
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}
*/
/*
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}
*/
/*
- (void)viewWillDisappear:(BOOL)animated {
	[super viewWillDisappear:animated];
}
*/
/*
- (void)viewDidDisappear:(BOOL)animated {
	[super viewDidDisappear:animated];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}

- (void)dealloc {
	[name release];
	[logoImg release];
	[tags release];
	[newsBtn release];
	[eventsBtn release];
	[siteBtn release];
	[group release];
    [super dealloc];
}


@end

